package canvas;






import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

import objetos.CanvasGame;
import objetos.GamePanel;
import objetos.myCanvas;

public class CanvasMenuSelectDificuldade extends myCanvas{

	public static CanvasMenuSelectDificuldade instance = null;


	BufferedImage menuImage;

	BufferedImage easyOn;
	BufferedImage mediumOn;
	BufferedImage hardOn;
	BufferedImage menugameOn;
	
	BufferedImage botaoVoltarImg;

	BufferedImage botaoVoltarOnImg;
	
	boolean voltarOn;

	long timerCompra, timerVenda;

	boolean mouseOverEasy = false;
	boolean mouseOverMedium = false;
	boolean mouseOverHard = false;

	Random rnd = new Random();

	long diftime, timerCLick;

	public CanvasMenuSelectDificuldade() {

		menuImage = GamePanel.loadImage("./../bgBack.png");   // imagem de fundo arvores

		easyOn = GamePanel.loadImage("./../easyOn.png");
		mediumOn = GamePanel.loadImage("./../mediumOn.png");
		hardOn = GamePanel.loadImage("./../hardOn.png");
		
		botaoVoltarImg = GamePanel.loadImage("./../botaoVoltar.png");

		botaoVoltarOnImg = GamePanel.loadImage("./../botaoVoltarOn.png");

		menugameOn = GamePanel.loadImage("./../levelselection2.png");

		instance = this;		


	}

	@Override
	public void SimulaSe(long diftime) {
		this.diftime = diftime;
		//System.out.print("\n MAPA ATUAL DO SHOP => " + CanvasGame.MapaAtual+ "\n");
		timerCLick += this.diftime;
		checaMouseLoja();

	}

	private void checaMouseLoja() {


		//easy
		if(CanvasGame.instance.MouseX > 268 && CanvasGame.instance.MouseX < 390 && CanvasGame.instance.MouseY > 193 && CanvasGame.instance.MouseY < 228){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;

				CanvasGame.instance.heroi.life = 100;

				CanvasGame.instance.gerenciaFases.mudaFase(1);
				CanvasGame.instance.heroi.X = 100;
				CanvasGame.instance.heroi.Y = 315;

				CanvasGame.instance.contagemRegressiva = 200;

				CanvasGame.instance.dificuldadeFacil = true;
				CanvasGame.instance.dificuldadeMedio = false;
				CanvasGame.instance.dificuldadeDificil = false;


				GamePanel.canvasAtivo = CanvasGame.instance;
			}
			mouseOverEasy = true;
		}else{
			mouseOverEasy = false;
		}

		// medium
		if(CanvasGame.instance.MouseX > 268 && CanvasGame.instance.MouseX < 390 && CanvasGame.instance.MouseY > 238 && CanvasGame.instance.MouseY < 273){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;
				CanvasGame.instance.heroi.massa = 220;

				CanvasGame.instance.contagemRegressiva = 200;
				
				CanvasGame.instance.gerenciaFases.mudaFase(1);
				CanvasGame.instance.heroi.X = 100;
				CanvasGame.instance.heroi.Y = 315;

				CanvasGame.instance.heroi.life = 100;

				CanvasGame.instance.dificuldadeFacil = false;
				CanvasGame.instance.dificuldadeMedio = true;
				CanvasGame.instance.dificuldadeDificil = false;

				GamePanel.canvasAtivo = CanvasGame.instance;
			}
			mouseOverMedium = true;
		}else{
			mouseOverMedium = false;
		}

		// hard
		if(CanvasGame.instance.MouseX > 268 && CanvasGame.instance.MouseX < 390 && CanvasGame.instance.MouseY > 283 && CanvasGame.instance.MouseY < 318){
			if(CanvasGame.instance.FIRE == true && timerCLick > 500){
				timerCLick = 0;
				CanvasGame.instance.FIRE = false;
				CanvasGame.instance.heroi.massa = 300;


				CanvasGame.instance.contagemRegressiva = 200;

				CanvasGame.instance.heroi.life = 100;
				CanvasGame.instance.gerenciaFases.mudaFase(1);
				CanvasGame.instance.heroi.X = 100;
				CanvasGame.instance.heroi.Y = 315;

				CanvasGame.instance.dificuldadeFacil = false;
				CanvasGame.instance.dificuldadeMedio = false;
				CanvasGame.instance.dificuldadeDificil = true;

				GamePanel.canvasAtivo = CanvasGame.instance;
			}
			mouseOverHard = true;
		}else{
			mouseOverHard = false;
		}

		
		
		// voltar
				if(CanvasGame.instance.MouseX > 227 && CanvasGame.instance.MouseX < 392 && CanvasGame.instance.MouseY > 373 && CanvasGame.instance.MouseY < 408){
					if(CanvasGame.instance.FIRE == true && timerCLick > 500){
						timerCLick = 0;
						CanvasGame.instance.FIRE = false;

						if (CanvasMenuSelectDificuldade.instance == null) {
							CanvasMenuPrincipal2 menuPrincipal2 = new CanvasMenuPrincipal2();

						}
						GamePanel.canvasAtivo = CanvasMenuPrincipal2.instance;
					}
					
					voltarOn = true;
				}else{
					voltarOn = false;
				}




	}

	public void DesenhaSe(Graphics2D dbg) {


		dbg.drawImage(menuImage, 0, 0, null); // tamanho da imagem


		dbg.drawImage(menugameOn, GamePanel.WIDTH/2+328/2, GamePanel.PHEIGHT/2-194/2, null); // tamanho da imagem
		
		dbg.drawImage(botaoVoltarImg, GamePanel.WIDTH/2+440/2, GamePanel.PHEIGHT/2+254/2, null); // tamanho da imagem


		dbg.setColor(Color.RED);
		//dbg.drawRect(268, 193, 122, 35);  // easy
		if(mouseOverEasy){
			dbg.drawImage(easyOn, 268, 193, null);
		}
		//dbg.drawRect(268, 238, 122, 35);  //mapeamento link +45 em y medium
		if(mouseOverMedium){
			dbg.drawImage(mediumOn, 268, 238, null);
		}

		//dbg.drawRect(268, 283, 122, 35);  //mapeamento link + 90 em y hard
		if(mouseOverHard){
			dbg.drawImage(hardOn, 268, 283, null);
		}
		
		
		if(voltarOn == true){
			dbg.drawImage(botaoVoltarOnImg,GamePanel.WIDTH/2+440/2, GamePanel.PHEIGHT/2+254/2, null);  // som
			
		}


	}

	@Override
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		int keyCode = e.getKeyCode();


		//CanvasGame.instance.dinheiro = 0;

		//CanvasGame.instance.listadePetdoveiculo.clear();
		//CanvasGame.instance.listadePetSystem.clear();

		//if (keyCode == KeyEvent.VK_ENTER) {
		//	GamePanel.canvasAtivo = CanvasGame.instance;	
		//}

	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		//System.out.print("MOVEU O MOUSEEEEEEEEEEEEE ");


	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}


	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		//System.out.print("Clicou AEEEEEEEEEEEEEEH ");
		CanvasGame.instance.MouseX = e.getX();
		CanvasGame.instance.MouseY = e.getY();
		int cont = 0;

	}

	public static BufferedImage loadImage(String source) {
		BufferedImage image = null;
		try {
			BufferedImage tmp = ImageIO.read(CanvasGame.instance.getClass()
					.getResource(source));
			image = new BufferedImage(tmp.getWidth(), tmp.getHeight(),
					BufferedImage.TYPE_INT_ARGB);
			image.getGraphics().drawImage(tmp, 0, 0, null);
			tmp = null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return image;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.print("CLICOU NO MOUSE AEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEH");

	}



}
